package cn.tedu.ivos2.dictoption.service.impl;

import cn.tedu.ivos2.dictoption.mapper.DictOptionMapper;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos2.dictoption.pojo.entity.DictOption;
import cn.tedu.ivos2.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos2.dictoption.service.DictOptionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DictOptionServiceImpl implements DictOptionService {
    @Autowired
    DictOptionMapper  dictOptionMapper;
    public List<DictOptionVO> search(DictOptionQuery dictOptionQuery) {
        return dictOptionMapper.search(dictOptionQuery);
    }
    public void save(DictOptionSaveParam dictOptionSaveParam) {
        DictOption dictOption = new DictOption();
        BeanUtils.copyProperties(dictOptionSaveParam, dictOption);
        if (dictOption.getId() ==null) {
            dictOption.setCreateTime(new Date());
            dictOptionMapper.save(dictOption);
        }else {
            dictOption.setUpdateTime(new Date());
            dictOptionMapper.update(dictOption);
        }
    }
    public void delete(Long id) {
        dictOptionMapper.deleteById(id);
    }
}
